package com.zysc.processflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zysc.processflow.common.base.BaseService;
import com.zysc.processflow.entity.Brand;
import com.zysc.processflow.entity.Category;
import com.zysc.processflow.mapper.BrandMapper;
import com.zysc.processflow.mapper.CategoryMapper;
import com.zysc.processflow.service.IBrandService;
import com.zysc.processflow.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryService extends BaseService<CategoryMapper, Category> implements ICategoryService {

    @Autowired
    private CategoryMapper categoryMapper;


    /**
     * 根据父节点查询子节点
     * @param pid
     * @return
     */
    public List<Category> queryCategoriesByPid(Long pid) {
        LambdaQueryWrapper<Category> categoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        categoryLambdaQueryWrapper.eq(Category::getParentId,pid);
        return this.categoryMapper.selectList(categoryLambdaQueryWrapper);
    }

    /**
     * 根据ids查询分类名称
     * @param ids
     * @return
     */
    public List<String> queryNamesByIds(List<Long> ids){
        List<Category> categories = this.categoryMapper.selectBatchIds(ids);
        return categories.stream().map(category ->category.getName()).collect(Collectors.toList());
    }


    public List<Category> queryCategoriesByBid(Long bid) {
        return this.categoryMapper.queryCategoriesByBid(bid);
    }
}
